<template>
    <div v-if="modalState">
        <Modal :mask-closable="false" transfer v-model="modalState" fullscreen title="文件" @on-cancel="cancel" class="modal-content-layout">
            <!--startprint1-->
            <component :is="comp" :type="printInfo.type" :printInfo="printInfo.info" ref="component">
            </component>
            <!--endprint1-->
            <Spin size="large" fix v-show="spinShow">
                <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
                <div>文件加载中</div>
            </Spin>

            <div slot="footer">
                <Button class="btn" type="primary" @click="close">{{$t('取消')}}</Button>
                <Button class="btn" type="primary" @click="onDownLoad">{{$t('下载')}}</Button>
                <Button class="btn" type="primary" @click="onPrint">{{$t('打印')}}</Button>
            </div>
        </Modal>
    </div>

</template>


<script>

import useCompToPDF from '@/util/useCompToPDF'
import capitalPrint from './capital'
import catPrint from './cat'
import downPaymentPrint from './downPayment'
import fatPrint from './fat'
import fixedAssetPrint from './fixedAssetPrint'
import { printPage } from './print'
import satPrint from './sat'
let exportPDF = null;

export default {
    // props: ['printInfo'],
    components: {
        catPrint,
        fatPrint,
        satPrint,
        downPaymentPrint,
        fixedAssetPrint,
        capitalPrint
    },
    data() {
        return {
            modalState: false,
            comp: "",
            compType: {
                'CAT': 'catPrint',
                'SAT': 'satPrint',
                'FAT': 'fatPrint',
                'SOC': 'capitalPrint',
                'PAY1': 'downPaymentPrint',
                'PAY2': 'downPaymentPrint',
                'PAY3': 'downPaymentPrint',
                'CAP': 'fixedAssetPrint',
            },
            printInfo: {}
        }
    },
    mounted() {
        const obj = {
            'CAT': this.$t('交付验收'),
            'SAT': this.$t('供应商处预验收'),
            'FAT': this.$t('最终验收'),
            'SOC': this.$t('确定供应商'),
            'PAY1': this.$t('支付首期款'),
            'PAY2': this.$t('第二次付款'),
            'PAY3': this.$t('第三次付款'),
            'CAP': this.$t('转固'),
        }

        exportPDF = useCompToPDF({fileName: obj[this.$route.query.typeName] + ".pdf"})
    },
    methods: {
        close(){
            this.modalState = false
        },
        open(printInfo) {
            this.printInfo = printInfo
            this.comp = this.compType[printInfo.type]
            this.modalState = true
        },
        onPrint() {



            let prnhtml = document.getElementById('printWrapId').innerHTML


            let iframe = document.createElement('iframe')
            iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
            var doc = null;
            document.body.appendChild(iframe)

            doc = iframe.contentWindow.document;

            let style = '';
            switch (this.printInfo.type) {
                case 'CAT':
                    style = '.print{padding: 55px;}'
                    break;
                case 'SOC':

                    this.$router.push({
                        path: "/capital",
                        query: {
                            id: this.printInfo.info.id
                        }
                    })

                    return;
                    // style = '.print {width: 1320px;}.print {transform: scale(0.3, 0.3);transform-origin: left top;padding: 32px;padding-top: 80px !important;}.tLogo {display: inline-block;z-index: 111;-webkit-print-color-adjust: exact;}.head-title {text-align: center;background-color: #5c6f7b !important;font-weight: bold;font-size: 26px;line-height: 40px;color: #FFFFFF !important;-webkit-print-color-adjust: exact;border: #000 solid 1px;}.label {font-size: 14px;font-weight: bold;color: #333333;line-height: 20px;padding: 0;margin: 0;border: none;}.desc {font-size: 14px;color: #333333;}.head-wrap ul {display: inline-block;}.head-wrap ul.r {float: right;padding-right: 60px;}.head-wrap li {margin-top: 10px;}.head-wrap li .label {width: 180px;display: inline-block;text-align: left;border: none;}.head-wrap li .ipt {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;}.bg-head {background: #d9d9d9 !important;-webkit-print-color-adjust: exact;}.bg-head span {padding-left: 3px;font-weight: bold;font-size: 14px;text-decoration: underline;color: #333333;}.ipt-content-wrap ul {padding: 7px 0 0 0;}.ipt-content-wrap li {display: inline-block;padding-bottom: 7px;vertical-align: top;}.ipt-content-wrap li.bp {width: 208px;}.ipt-content-wrap li.bp1 {width: 262px;}.ipt-content-wrap li.bp2 {width: 360px;}.ipt-content-wrap li .radio-br {width: 60px;height: 20px;border: #333 solid 1px;display: inline-block;vertical-align: bottom;margin-right: 3px;}.pTextarea {border: #333 solid 1px;min-height: 115px;margin: 5px 0;padding: 5px;font-size: 14px;}.department {border: #333 solid 1px;}.department .info-wrap li {display: inline-block;width: 180px;vertical-align: top;padding-bottom: 0;}.department .info-wrap li span {display: block;text-align: left;}.department .info-wrap li .label {height: 20px;}.department .info-wrap li .ipt {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;margin-top: 44px;height: 22px;line-height: 22px;}.department .label-title {text-decoration: underline;}.iptImage {height: 40px;padding-top: 26px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: content-box;}.iptImage img {height: 40px;width: auto;padding: 0;}.table-list {border: #333 solid 1px;margin-top: 5px;}.table-list .table {padding-left: 5px;margin-bottom: 0;padding-top: 0;margin-top: 0;padding-top: 0;}.table-list .table li {color: #333333;display: inline-block;margin-right: 40px;border-radius: 0;}.table-list .table li:nth-child(1) {width: 35px;text-align: left;}.table-list .table li:nth-child(2) {width: 120px;text-align: left;}.table-list .table li:nth-child(3) {width: 180px;}.table-list .table li:nth-child(4) {width: 360px;}.table-list .table li:nth-child(5) {width: 60px;text-align: right;}.table-list .table li:nth-child(6) {width: 60px;text-align: right;}.table-list .table li:nth-child(7) {width: 120px;text-align: right;}.table-list .table li.ipt {border-bottom: #333 solid 1px;padding-bottom: 1px;font-size: 14px;vertical-align: text-bottom;}.table-list .info-wrap {margin: 5px;padding-top: 0;}.table-list .info-wrap li {display: inline-block;vertical-align: bottom;margin-right: 200px;padding-bottom: 0;}.table-list .info-wrap li:last-child {margin-right: 0;}.table-list .info-wrap li span {display: block;text-align: left;}.table-list .info-wrap li .ipt {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;padding-top: 35px;height: 20px;}.approval {margin-top: 5px;}.approval .br {border: #333333 solid 1px;margin: 3px 0;}.approval .btm-br {border-top: #333333 solid 1px;padding: 3px;}.approval .info-wrap {margin: 5px;padding-top: 0;padding-left: 60px;}.approval .info-wrap li {display: inline-block;vertical-align: bottom;margin-right: 200px;padding-bottom: 0;}.approval .info-wrap li:last-child {margin-right: 0;}.approval .info-wrap li span {display: block;text-align: left;}.approval .info-wrap li .ipt {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;padding-top: 66px;}.end-wrap {text-align: right;padding-right: 74px;}.end-wrap .number {border-bottom: #333333 solid 1px;width: 120px;display: inline-block;margin-left: 40px;}'
                    break;
                case 'PAY':
                    style = '.print {padding: 40px;}.page-title .z {font-weight: bold;font-size: 16px;display: block;}.page-title .f {font-size: 14px;}.head-info-wrap {position: relative;}.head-info-wrap .desc1 {font-size: 12px;width: 224px;text-align: right;display: inline-block;padding-right: 7px;font-weight: 600;box-sizing: border-box;}.head-info-wrap .desc2 {font-weight: 600;font-size: 12px;padding-left: 51px;}.head-info-wrap table {border-color: black !important;width: 490px;border: #000 solid 2px;vertical-align: bottom;}.head-info-wrap table tr td {font-size: 12px;padding: 0 2px;border: #000 solid 2px;height: 20px;line-height: 18px;}.head-info-wrap table tr td p, .head-info-wrap table tr td span {font-size: 12px;}.head-info-wrap table tr td:nth-child(1) {width: 77px;}.head-info-wrap table tr td:nth-child(2) {width: 17px;}.head-info-wrap table tr td:nth-child(3) {width: 97px;text-align-last: justify;text-align: justify;text-justify: distribute-all-lines;}.head-info-wrap table tr td:nth-child(4) {width: 33px;text-align: center;}.head-info-wrap table tr td .radio-image {margin: 0 auto 0;}.head-info-wrap table tr td .left-label {display: inline-block;width: 56px;}.head-info-wrap table tr td.no-btm-br {border: none;}.head-info-wrap table tr td .justify {width: 56px;}.head-info-wrap .right-wrap {display: inline-block;width: calc(100% - 490px);position: absolute;right: 0;bottom: 0;}.head-info-wrap .right-wrap ul li span {font-size: 12px;display: block;}.head-info-wrap .right-wrap ul li span:nth-child(1) {line-height: 1;margin-left: 4px;}.head-info-wrap .right-wrap ul li .ipt {height: 20px;border-bottom: #333 solid 1px;width: 125px;margin-left: 95px;margin-bottom: 10px;font-weight: bold;}.radio-image img {width: 14px;}.c-text {font-size: 12px;font-weight: 600;}.money-wrap .money-type {border: #000000 solid 2px;padding: 1px 5px;width: 75px;display: inline-block;}.money-wrap .money-type .radio-image {display: inline-block;}.my-content {display: inline-block;width: calc(100% - 80px);padding-left: 5px;vertical-align: top;}.my-content .ctn-wrap {border-bottom: #000 solid 1px;}.my-content .ctn-wrap ul {height: 22px;display: inline-block;}.my-content .ctn-wrap ul li {width: 16px;height: 20px;display: inline-block;border-right: #000 solid 1px;border-top: #000 solid 1px;vertical-align: text-top;line-height: 20px;text-align: center;font-weight: bold;}.my-content .ctn-wrap ul li:first-child {border-left: #000 solid 1px;}.my-content .ctn-wrap .p-t {display: inline-block;font-size: 12px;padding-left: 5px;vertical-align: bottom;}.my-content .ipt {width: 50px;height: 18px;border: #000 solid 1px;display: inline-block;margin-left: 15px;margin-top: 7px;}.my-content .c-text {margin-left: 150px;vertical-align: top;position: relative;top: 8px;}.dept-branch {font-size: 12px;}.dept-branch .ipt {height: 20px;line-height: 20px;border-bottom: #000 solid 1px;font-weight: bold;font-size: 12px;width: 200px;}.label {border: none !important;}.invoice-attached .label {font-size: 12px;font-weight: bold;color: #000000;padding: 0;}.invoice-attached td {border: #000 solid 2px;padding: 5px !important;}.manager .item {width: calc(100% / 3);display: inline-block;}.manager1 .item {width: calc(100% / 3);display: inline-block;}.manager1 .item:first-child {width: calc(100% / 3 * 2);}.money-table {border-collapse: collapse;box-sizing: border-box;float: left;}.money-table td {box-sizing: border-box;border-collapse: collapse;}'
                    break;
                case 'FAT':
                    style = '.print {padding: 55px;}.hl2 {height: 52px;line-height: 52px;width: 100%;text-align: center;}.hl1 {height: 26px;line-height: 26px;width: 100%;text-align: center;}'
                    break;
                case 'CAP':
                    style = '.print {padding: 50px 32px 32px 32px;width: 1200px;}.tLogo {position: absolute !important;display: inline-block;left: initial;top: 50px;right: 55px;}.title-wrap {width: 100%;text-align: center;font-family: SimSun;}.title-wrap .name {font-weight: 600;font-size: 19px;line-height: 40px;}.title-wrap .name-en {font-weight: 600;font-size: 14px;margin-top: 3px;line-height: 0;}.head-wrap .left {display: inline-block;}.head-wrap .right {display: inline-block;float: right;vertical-align: bottom;padding-right: 80px;}.head-wrap .line {border-bottom: #333 solid 1px;height: 20px;vertical-align: text-bottom;width: 120px;display: inline-block;margin-left: 10px;}.bg-head {background: #d9d9d9 !important;-webkit-print-color-adjust: exact;}.bg-head span {padding-left: 3px;font-weight: bold;font-size: 14px;text-decoration: underline;color: #333333;}.label {font-size: 14px;font-weight: bold;color: #333333;line-height: 20px;padding: 0;margin: 0;border: none;}.info-wrap {margin-top: 17px;}.info-wrap li {display: inline-block;vertical-align: top;padding-bottom: 0;margin-right: 120px;}.info-wrap li:last-child {margin-right: 0;}.info-wrap li span {display: block;text-align: left;}.info-wrap li .label {height: 20px;display: inline-block;margin-right: 65px;font-weight: normal;}.info-wrap li .ipt {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;height: 22px;line-height: 22px;}.iptLine {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;height: 22px;line-height: 22px;text-align: center;}.label1 {text-align: left;width: 106px;}.ipt-content-wrap ul {padding: 7px 0 0 0;}.ipt-content-wrap li {display: inline-block;padding-bottom: 7px;vertical-align: top;}.ipt-content-wrap li.bp {width: 208px;}.ipt-content-wrap li.bp1 {width: 262px;}.ipt-content-wrap li.bp2 {width: 365px;}.ipt-content-wrap li .radio-br {width: 60px;height: 20px;border: #333 solid 1px;display: inline-block;vertical-align: bottom;margin-right: 3px;}.table-list {margin-top: 5px;}.table-list .table {padding-left: 5px;margin-bottom: 0;padding-top: 0;margin-top: 0;padding-top: 0;}.table-list .table li {color: #333333;display: inline-block;margin-right: 30px;border-radius: 0;}.table-list .table li:last-child {margin-right: 0;}.table-list .table li:nth-child(1) {width: 35px;text-align: left;}.table-list .table li:nth-child(2) {width: 120px;text-align: left;}.table-list .table li:nth-child(3) {width: 180px;}.table-list .table li:nth-child(4) {width: 360px;}.table-list .table li:nth-child(5) {width: 60px;text-align: right;}.table-list .table li:nth-child(6) {width: 60px;text-align: right;}.table-list .table li:nth-child(7) {width: 120px;text-align: right;}.table-list .table li.ipt {padding-bottom: 1px;font-size: 14px;}.table-list .info-wrap {margin: 5px;padding-top: 0;}.table-list .info-wrap li {display: inline-block;vertical-align: bottom;margin-right: 200px;padding-bottom: 0;}.table-list .info-wrap li:last-child {margin-right: 0;}.table-list .info-wrap li span {display: block;text-align: left;}.table-list .info-wrap li .ipt {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;padding-top: 35px;height: 20px;}.end-wrap {text-align: right;padding-right: 14px;padding-top: 20px;}.end-wrap .number {border-top: #333333 solid 1px;border-bottom: #333333 solid 1px;width: 120px;display: inline-block;margin-left: 40px;position: relative;}.end-wrap .number::before {content: \'\';width: 120px;border: #333333 solid 1px;position: absolute;top: 24px;right: 0;}.tb-wrap .label-title {display: inline-block;margin-right: 60px;}.tb-wrap ul {display: inline-block;vertical-align: top;padding-top: 0;}.tb-wrap ul li {display: block;}.text-p-wrap .left {display: inline-block;width: 720px;}.text-p-wrap .right {display: inline-block;}.info-wrap-write {padding-top: 20px !important;border: #333 solid 1px;}.info-wrap-write li {display: inline-block;width: 180px;vertical-align: top;padding-bottom: 0;}.info-wrap-write li span {display: block;text-align: left;}.info-wrap-write li .label {height: 20px;}.info-wrap-write li .ipt {width: 180px;border-bottom: #333333 solid 1px;font-size: 13px;color: #333333;display: inline-block;font-weight: bold;padding-left: 3px;box-sizing: border-box;margin-top: 20px;height: 40px;}'
                    break;
                case 'SAT' :
                    style = '.print{padding: 55px;}'
                    break;
            }

            doc.write(`<style> *{font-family: "Roboto",arial,sans-serif !important;font-size: 15px;list-style: none;}.wrap{padding-top:100px;padding-bottom:100px;background:#404040;}.print-wrap{width:21cm;margin:0 auto;}.print{width:21cm;height:auto;margin:0 auto 50px;background:#ffffff;padding:20px;box-sizing:border-box;page-break-after:always;position:relative;}.print:last-child{margin-bottom:0;}.print .header{margin-bottom:30px;border-bottom:1px solid #000;}.print .header .logo{display:inline-block;width:110px;vertical-align: bottom;}.print .header .title-wrap{font-family:SimSun;width:calc(100% - 138px);display:inline-block;}.print .header .title-wrap p{text-align:center;line-height:25px;}.print .header .title-wrap .name{font-weight:600;font-size:21px;line-height:1;}.print .header .title-wrap .name-en{font-weight:600;font-size:14px;margin-left:55px;margin-top:3px;line-height:0;}.print table{position:relative;width:100%;table-layout:fixed;border-color:#000;border-width:2px;}.print table .borderNone{border:none;border-color:transparent;}.print table td{padding:5px;vertical-align:top;line-height: 1;height: 10px}.print table .text{font-size:14px;margin: 0;line-height: 26px}.print table .text-en{font-size:15px;font-weight:500;line-height: 26px;margin:0;}.print table p{line-height:26px !important;color:#333;padding: 0 !important;}.w50{width:50%;}.w100{width:100%;}.w33{width:calc(100% / 3);}.radio{display:inline-block;width:12px;height:12px;border:#333 solid 2px;line-height:1;margin:0;padding:0;vertical-align:baseline;margin-right:5px;}.underline{text-decoration:underline;}.ft{position:fixed;bottom:20px;color:#000;width:calc(100% - 32px);left:16px;font-size:14px;display:none;}.ft span{font-weight:500;position:absolute;right:0;bottom:0;}.tLogo{position:fixed;top:28px;left:1178px;display:none;}.tLogo img{width:50px;}.bold{font-weight:bold;}.underline{text-decoration:underline;}.descText{white-space:pre;line-height:17px !important;}.nowrap td{text-align:center;}.nowrap p{white-space:nowrap;}.breakWord p{word-break:break-all;}.signPathWrap img{width:50%;display:inline-block;}.list-item-text td{line-height:1;word-break:break-all;padding:5px 0 !important;}@media print{.print{margin-bottom:0 !important;width:100%;}.wrap{padding:0;}.ft{display:inline-block;}@page{size:auto;margin:0mm;}}.selectActive{position:relative;}.selectActive:before{content:"✓";color:#333;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);font-weight:bold;}</style>
                        <style>${style}</style>
                        <body>${prnhtml}</body>`);




            console.log(document, 'document.innerHTML')

            doc.write(`${document.innerHTML}`)
            // doc.body.innerHTML = prnhtml
            // doc.head.innerHTML = head

            console.log(doc, 'docdoc')
            doc.close();

            iframe.contentWindow.focus();

            printPage(iframe.contentWindow)
            if (navigator.userAgent.indexOf("MSIE") > 0) {
                document.body.removeChild(iframe);
            }
        },
        onDownLoad() {
            // console.log(this.$refs.printWrap.parent)
            exportPDF(document.getElementById('printWrapId'))
            //  htmlToPdf('printWrapId','123123123.pdf')
        }
    }
}
</script>
<style>
::v-deep .ivu-modal-body {

}
</style>
